package xyf.p02.stack_queue;

import java.util.LinkedList;
import java.util.Queue;

/**
 * ClassName: P0225_StackByTwoQueue
 * Description:
 * Author: xyf
 * Date: 9/3/22 6:20 PM
 * Version: 1.0
 **/
public class P0225_StackByTwoQueue
{
    class MyStack
    {

        private Queue<Integer> queue = new LinkedList<>();

        private Queue<Integer> help = new LinkedList<>();

        public MyStack()
        {

        }

        public void push(int x)
        {
            while (!queue.isEmpty())
            {
                help.offer(queue.poll());
            }
            queue.offer(x);
            while (!help.isEmpty())
            {
                queue.offer(help.poll());
            }
        }

        public int pop()
        {
            return queue.poll();
        }

        public int top()
        {
            return queue.peek();
        }

        public boolean empty()
        {
            return queue.isEmpty();
        }
    }
}